package gd.qaq.blue.bluesname;

import gd.qaq.blue.bluesname.commands.BluesNameCommands;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * 反编译的同学~好好学着点噢
 * 作者:blue qq:862899738
 */
public final class BluesName extends JavaPlugin {
    public static BluesName plugin;
    public static FileConfiguration config;

    @Override
    public void onEnable() {
        // Plugin startup logic
        plugin = this;
        loadDatas();
        Bukkit.getPluginCommand("bluesname").setExecutor(new BluesNameCommands());
    }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
        super.onDisable();
    }

    /**
     * Query data from database
     */
    private void loadDatas() {
        if (!this.getDataFolder().exists()) {
            this.getDataFolder().mkdirs();
            this.saveDefaultConfig();
        }
        config = this.getConfig();
    }

    public void reload(Player p) {
        if (p.isOp()) {
            try {
                this.reloadConfig();
                config = this.getConfig();
                success(p, "插件重载成功");
            } catch (Exception e) {
                e.printStackTrace();
                error(p, "插件重载失败!");
            }
        }
    }
    public static String colorFormat(String str) {
        return str.replace("&", "§");
    }

    public static void success(CommandSender p, String str) {
        p.sendMessage("§f[§aBluesName§f]§a" + colorFormat(str));
    }

    public static void error(CommandSender p, String str) {
        p.sendMessage("§f[§cBluesName§f]§c" + colorFormat(str));
    }
}
